;(function (window, angular) {
    'use strict';
    var material = angular.module('Service.Material', []);

    // 零件的公共服务
    material.factory('MaterialService', ['ybWidget', function (ybWidget) {
        /**
         * 批量选择储位
         * @param warehouseCode 仓库编码
         * @param materialList 零件列表
         */
        function multiSelDepot (warehouseCode, materialList) {
            var selectedCount = 0;
            angular.forEach(materialList, function (item) {
                if (item.isChecked) selectedCount += 1;
            });
            if (selectedCount <= 0) {
                ybWidget.ShowMessage('请先选择零件！');
                return;
            }
            var param = {
                warehouseCode: warehouseCode
            };
            ybWidget.DepotSelector(param).then(function (data) {
                angular.forEach(materialList, function (item) {
                    if (item.isChecked) {
                        item.warehouseCode = data.warehouseCode;
                        item.areaCode = data.areaCode;
                        item.locationCode = data.locationCode;
                    }
                })
            })
        }

        return {
            multiSelDepot: multiSelDepot
        }
    }])
})(window, angular);